import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Pavo here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Pavo extends Enemigo
{
   
    private int dir;
    private int cont=0;
    
    private GreenfootImage[] i= new GreenfootImage[2];
    
    /**
     * 
     * Act - do whatever the Pavo wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public Pavo(int d){
        super();
        dir=d;
        i[0]=new GreenfootImage("turkey2.png");
        i[1]=new GreenfootImage("turkey2.png");
        i[1].mirrorHorizontally();
     }
    public void act() 
    {
        move();
    }    
    
    public void move(){
       
       if(dir==2) {
            setImage(i[1]);
            setLocation(getX()-4,getY());
            cont++;
            if(cont==500){
              dir=1;
              cont=0;
            }
            }
       if(dir==1){
             setImage(i[0]);
             setLocation(getX()+4,getY());
             cont++;
               if(cont==500){
                 dir=2;
                 cont=0;
                }
                }
        java.util.List c;
        c=getObjectsInRange(500, Cartman.class) ;
        World w=getWorld();
        Cartman ca=((Mundo)getWorld()).getCartman();
        if(!c.isEmpty()){
            
            turnTowards(ca.getX(),ca.getY());
            
            if(getRotation()<180)
             setImage(i[0]);
            if(getRotation()>=180)
             setImage(i[1]);
            
            move(1);
            
        }
    }
}

